<template>
  <el-container>
    <el-header>
      <div>
        <img src="/static/img/avatar/1.jpg" alt="头像" class="back-header-avatar" />
        <h2 class="store">电商后台管理系统</h2>
      </div>
      <el-button type="text" plain @click="tuichu" style="padding:3px 20px;">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isOpen?'70px':'200px'">
        <div class="elIttle" @click="toggle">|||</div>
          <el-menu
            router
            class="el-menu-vertical-demo"
            background-color="#EBC4B6"
            text-color="#4884a4"
            active-text-color="#6CA984"
            :unique-opened="true"
            :default-active="$route.path"
            :collapse-transition="false"
            :collapse="isOpen"
            >
            <el-submenu v-for="item in menuList" :key="item.menuId" :index="item.menuId+''">
              <template slot="title">
                <i :class="item.iconName" style="color:#6CA984;"></i>
                <span>{{item.authName}}</span>
              </template>
              <el-menu-item :index="subItem.path+''" v-for="subItem in item.children" :key="subItem.id">
                <i :class="subItem.iconName" style="color:#6CA984;"></i>
                <span>{{subItem.authName}}</span>
              </el-menu-item>
            </el-submenu>
          </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      // 左侧菜单栏数据
      // menuList: null,
      menuList:[],
      isOpen:false,
      isCollapse:true
    };
  },
  created() {
    this.getMenu();
  },
  methods: {
    async getMenu() {
      const {data:res} = await this.$http.get("selMenu");
      // console.log(res);
      if (res.status !== 200) {
        this.$message.error('查询数据失败');
      } else {
        let menuList = res.message;
        for(let i in menuList){
          // console.log(menuList[i].menuId);
          let variate = menuList[i].menuId;
          const {data:childRes} = await this.$http.post("selChild",{variate});
          // console.log(childRes);
          if(childRes.status != 200){
            this.$message.error('查询数据失败');
          }else{
            menuList[i].children = childRes.message;
          }
        }
        // console.log(menuList);
        this.menuList = menuList;
      }
    },
    toggle:function(){
      this.isOpen =! this.isOpen
      // console.log(this.isOpen);
    },
    handleOpen(key, keyPath) {
      // console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      // console.log(key, keyPath);
    },

    tuichu(){
      this.$router.push("/home");
    }
  }
};
</script>
<style>
.el-container.is-vertical {
  height: 100%;
}
.el-header {
  background-color: #4884A4;
  display: flex;
  justify-content: space-between;
}
.el-aside {
  background-color:	#EBC4B6;
}
.el-main {
  background-color: #f0f8ff;
}
.back-header-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 1px solid rgb(182, 185, 185);
  margin-top: 4px;
}
.store {
  position: absolute;
  top: -8px;
  left: 90px;
}
.el-button {
  margin: 12px 0;
}
.elIttle {
  color: #4884a4;
  background-color: #4884a447;
  text-align: center;
  height: 30px;
  line-height: 30px;
  letter-spacing: 3px;
  font-size: 20px;
  cursor: pointer;
}
.el-menu-vertical-demo .el-submenu{
  width: 200px;
}
.el-submenu {
  width: 300px;
}
</style>
